<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <template #footer>
      <a-button key="1" @click="handleCancel">关闭</a-button>
      <a-button :hidden="disableSubmit" key="3" type="primary" :loading="loading" @click="handleOk">保存</a-button>
      <a-button :hidden="disableSubmit" key="2" type="primary" :loading="subLoading" @click="handleIsIssue">提交</a-button>
    </template>
    <noticeForm v-if="formType=='notice'" ref="realForm" @ok="submitCallback" @isLoading="isLoading" @close='close' :disabled="disableSubmit"/>
    <opinionForm v-if="formType=='opinion'" ref="realForm" @ok="submitCallback" @isLoading="isLoading" @close='close' :disabled="disableSubmit"/>
  </j-modal>
</template>

<script>

  import noticeForm from './noticeForm'
  import opinionForm from './opinionForm'

  export default {
    name: 'dailogModal',
    components: {
      noticeForm,
      opinionForm
    },
    props:{
      // 区分是通知公告or意见征集
      formType:{
        type:String,
        default:'notice'
      }
    },
    data () {
      return {
        title:'',
        width:1200,
        visible: false,
        disableSubmit: false,
        loading: false,
        subLoading: false
      }
    },
    methods: {
      add () {
        this.visible=true
        this.title='新增'
        this.$nextTick(()=>{
          this.$refs.realForm.addOrEdit();
        })
      },
      edit (record) {
        this.visible=true
        this.title='编辑'
        this.$nextTick(()=>{
          this.$refs.realForm.addOrEdit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      // 保存
      handleOk () {
        this.loading = true
        this.$refs.realForm.submitForm(0);
      },
      // 提交
      handleIsIssue () {
        this.subLoading = true
        this.$refs.realForm.submitForm(1)
      },
      submitCallback(){
        this.$emit('ok');
        this.loading = false
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      isLoading() {
        this.loading = false
        this.subLoading = false
      }
    }
  }
</script>